package web.dynamic.client;

import java.util.List;
import java.util.Map;

import com.extjs.gxt.ui.client.widget.form.Field;
import com.extjs.gxt.ui.client.widget.form.FormPanel;

public class DynForm implements DynType {

	@SuppressWarnings("unchecked")
	@Override
	public Object create(DynDef def) {
		FormPanel panel = new FormPanel();
	    //panel.setHeaderVisible(false);
	    
		List<Map<String,Object>> fields = (List<Map<String,Object>>)def.get("fields");
		
		for( Map<String,Object> f : fields ){
			Field fld = DCM.createField( (String)f.get("type") );
			// TODO: create mappers ( @see DCM.createField type factory ), mappers map proeprties to fields, they alows allow for fallbacks, ie in labels case the order would be displayName or name or none ( if showLabel == false );
			fld.setName( (String)f.get("name") );
			fld.setFieldLabel( (String)f.get("name") );
		    panel.add(fld);
		}
	    	
	    return panel;
	}
}
